import VueRouter from "vue-router";
import Vue from "vue";
import login from "@/views/login/login";
import layout from "@/views/layout/layout";
import user from "@/views/layout/user/user";
import data from "@/views/layout/data/data";
import company from "@/views/layout/company/company";
import question from "@/views/layout/question/question";
import subject from "@/views/layout/subject/subject";

import NProgress from "nprogress";
import "nprogress/nprogress.css";
Vue.use(VueRouter);
const router = new VueRouter({
  routes: [
    {
      path: "/",
      redirect: "/login",
      meta: {
        title: "登录",
      },
    },
    {
      path: "/login",
      component: login,
      meta: {
        title: "登录",
      },
    },
    {
      path: "/layout",
      component: layout,
      redirect: "/layout/subject",
      children: [
        {
          path: "/layout/user",
          component: user,
          meta: {
            title: "用户列表",
          },
        },
        {
          path: "/layout/company",
          component: company,
          meta: {
            title: "企业列表",
          },
        },
        {
          path: "/layout/data",
          component: data,
          meta: {
            title: "数据概览",
          },
        },
        {
          path: "/layout/question",
          component: question,
          meta: {
            title: "题库列表",
          },
        },
        {
          path: "/layout/subject",
          component: subject,
          meta: {
            title: "学科列表",
          },
        },
      ],
    },
  ],
});
router.beforeEach((to, from, next) => {
  NProgress.start();
  next();
}),
  router.afterEach((to, from) => {
    NProgress.done();
    document.getElementById("title").innerText = to.meta.title;
    console.log(to, from);
  });
export default router;
